package main

import (
	"fmt"

	"erp/config"
	"erp/middleware"
	"erp/model"
	"erp/router"

	"github.com/gin-gonic/gin"
)

func main() {
	config.Load()
	config.InitDB()
	// Auto migrate models
	_ = config.DB.AutoMigrate(&model.Product{}, &model.Order{}, &model.OrderItem{}, &model.Shipment{})

	r := gin.Default()
	r.Use(middleware.CORS())
	r.Use(middleware.Trace())

	router.Setup(r)

	addr := fmt.Sprintf(":%d", config.Cfg.Server.Port)
	r.Run(addr)
}